<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 判断响应成功还是失败 使用响应状态码-->
    <p class="my-p"></p>
    <script>
        const p=new Promise((resolve,reject)=>{
            const xhr=new XMLHttpRequest
        xhr.open('POST','http://hmajax.itheima.net/api/province')
        xhr.addEventListener('loadend',()=>{
            //响应状态码的判断
            if(xhr.status>200&&xhr.status<300)
            {
                resolve(JSON.parse(xhr.response))
            }
            else{
                reject(new Error(xhr.response))
            }
        })
        xhr.send()
    })
    //成功的状态
        p.then(result=>{
            console.log(resolve)
            document.querySelector('.my-p').innerHTML=result.list.join('<br>')
        }).catch(error=>{
            //错误对象需要使用详细console.dir(error)})的进行打印
            console.dir(error)
            document.querySelector('.my-p').innerHTML=error.message
        })
    </script>
</body>
</html>